/**
 * Copyright (c) 2022 KCloud-Platform-Official Authors. All Rights Reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 *   http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.laokou.rocketmq.consumer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.laokou.auth.client.user.UserDetail;
import org.laokou.common.core.utils.ConvertUtil;
import org.laokou.kafka.client.dto.OperateLogDTO;
import org.laokou.kafka.consumer.entity.SysOperateLogDO;
import org.laokou.kafka.consumer.mapper.SysOperateLogMapper;
import org.laokou.kafka.consumer.mapper.SysUserMapper;
import org.laokou.kafka.consumer.service.SysOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Kou Shenhai
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysOperateLogServiceImpl extends ServiceImpl<SysOperateLogMapper, SysOperateLogDO> implements SysOperateLogService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public void insertOperateLog(OperateLogDTO dto) {
        SysOperateLogDO logDO = ConvertUtil.sourceToTarget(dto, SysOperateLogDO.class);
        final UserDetail userDetail = sysUserMapper.getUserDetail(logDO.getCreator(),null);
        logDO.setDeptId(userDetail.getDeptId());
        baseMapper.insert(logDO);
    }
}
